<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    var damu = {
        name:"达姆",
        age:18,
        wife:{
            name:"冬雨",
            age:17,
            son:{
                name:"老付",
                age:7
            }
        }
    }


   /*Object.deepFreeze(damu)
        ---> Object.deepFreeze(wife)
            ---> Object.deepFreeze(son)*/


   //obj就是模板对象
   Object.deepFreeze = function (obj) {
        //["name","age","wife"]
       // ["name","age","son"]
        var propNames = Object.getOwnPropertyNames(obj)
        propNames.forEach((propName)=>{
            //prop:每一个propName对应的val
            var prop = obj[propName];
            if(typeof prop === "object" && prop !== null){
                //说明当前的prop是一个对象
                Object.deepFreeze(prop)
            }
        })
        //对obj实行一个浅冻结
        Object.freeze(obj)
   }

   Object.deepFreeze(damu)


  damu.wife.son.name="aaa"
  console.log(damu);
</script>
</html>